﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace WpfApplication1
{
    /// <summary>
    /// Interaction logic for MakeDeposit.xaml
    /// </summary>
    public partial class MakeDeposit : Page
    {
        public MakeDeposit()
        {
            InitializeComponent();
        }
        public static bool onlyNumeric(string text)
        {
            Regex regex = new Regex("[^0-9.-]+"); //regex that allows numeric input only
            return !regex.IsMatch(text);
        }
        private void textBox1_PreviewTextInput(object sender, TextCompositionEventArgs e)
        {
            e.Handled = !onlyNumeric(e.Text);
        }

        private void MakeDepositfun(object sender, RoutedEventArgs e)
        {
            TransactionsLogic TL = new TransactionsLogic();
           Nullable<decimal> MoneyDeposite;
            bool Dvalidation;
            Dvalidation = TL.ValidationTransaction(Profile.bankAccount.AccountCode, MakeDeposits.Text);
            if (Dvalidation == true)
            {
                MoneyDeposite = TL.Deposite(Profile.bankAccount.Credit, (decimal)double.Parse(MakeDeposits.Text));
                if (MoneyDeposite < 0)
                {

                    MessageBox.Show("Have no much credit !!");

                }
                else
                {
                    MessageBox.Show("your Balance now became  '" + MoneyDeposite + "'");
                }
            }
            else {
                MessageBox.Show("you Frogot to enter Credit >_< !!");
            }


        }
    }
}
